package test.solution;


import java.util.*;

public class Main1 {
    public static void main(String[] args) {

        List<String> sl = new ArrayList<String>();
        List<String> wl = new ArrayList<String>();

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        while (n-- > 0) {
            sl.add(scanner.next());
        }
        while (m-- > 0) {
            wl.add(scanner.next());
        }
        scanner.close();
        List<Set<String>> sPossibilities = new ArrayList<Set<String>>();
        for (String s : sl) {
            sPossibilities.add(possibility(s));
        }
        for (String w : wl) {
            int i = 0;
            for (Set<String> p : sPossibilities) {
                if (p.contains(w)) {
                    i++;
                }
            }
            System.out.println(i);
        }
    }

    static Set<String> possibility(String s) {
        Set<String> set = new TreeSet<String>();
        for (int i = 0; i < s.length(); i++) {
            String tmp = s.substring(0, i) + s.substring(i + 1, s.length());
            set.add(tmp);
        }
        return set;
    }
}
